package automatica.autoprove;


import java.io.File;

import javax.swing.JFrame;

import ui.Utility;
import ui.view.ShowFrame;

import com.maplesoft.externalcall.MapleException;
import com.maplesoft.openmaple.Engine;
import com.maplesoft.openmaple.EngineCallBacksDefault;

public class AutoProve {
	
	private String name;
	private Engine engine;
	private CallBacks callback;
	
	public AutoProve(Engine engine, CallBacks callback, String resultPath, String xslPath, String outputPath, String name, String proofPath){
		this.name = name;
		this.callback = callback;
		Map2GEOTHER normalForm = new Map2GEOTHER(resultPath, xslPath, outputPath);                                    
		for(int i = 0; i < normalForm.getPredicate4GEOTHER().size(); i++){
			MapleLink prove = new MapleLink(engine, name==null?"demo":Utility.deleteSpace(name).replace(".", ""),normalForm.getPredicate4GEOTHER().get(i));
		}
		showProof(proofPath, "auto-proof in GEOTHER: " + name);

		
	}

	public AutoProve(Engine engine, CallBacks callback, String data, String name, String proofPath){
		this.name = name;
		this.callback = callback;
		Map2GEOTHER normalForm = new Map2GEOTHER(data);                                    
		for(int i = 0; i < normalForm.getPredicate4GEOTHER().size(); i++){
			MapleLink prove = new MapleLink(engine, name==null?"demo":name,normalForm.getPredicate4GEOTHER().get(i)+(i==0?"":"#"+i));
		}
		showProof(proofPath, "auto-proof in GEOTHER: " + name);
	}
	

	
	public void showProof(String proofPath, String title){
		File proofFile = new File(proofPath);
		if(proofFile.exists()){
			proofFile.delete();
		}
		Utility.saveFile(null, "<html><head><style type='text/css'> span.text {color:black; font-family:verdana;font-size:110%;} span.status{color:rgb(160,160,160);}</style></head><body><div>" + callback.getOutput() + "</div>" +
				"</body></html>", proofFile);
		ShowFrame showFrame = new ShowFrame();
		
		showFrame.show(null,null,proofFile.toString());
		showFrame.setVisible(true);
		showFrame.setTitle(title);
		
	}

	
    
 

}
